package GUI;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.Timer;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.GridBagLayout;

import javax.swing.JComponent;
import javax.swing.JToggleButton;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JButton;

import java.awt.BorderLayout;
import java.awt.CardLayout;

import javax.swing.JScrollPane;

import java.awt.GridBagConstraints;

import javax.swing.ScrollPaneConstants;

import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyListener;
import org.jnativehook.mouse.NativeMouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class DO {

	public JFrame frame;
	public JPanel panel;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					DO window = new DO();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public DO() {
		

		initialize();

	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent arg0) {
				System.out.println("clouse");
			}
			@Override
			public void windowClosing(WindowEvent e) {				
				System.out.println("clouse");
				GlobalScreen.unregisterNativeHook();
				System.exit(1);

			}
		});
		frame.setMaximumSize(new Dimension(405, 405));
		frame.setSize(new Dimension(448, 300));
		frame.setPreferredSize(new Dimension(405, 405));
		frame.getContentPane().setName("DO");
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
		frame.setAlwaysOnTop(true);
				
		panel = new JPanel();
		//frame.getContentPane().add(panel);
		
		JScrollPane scrollPane = new JScrollPane(panel);
		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] {0};
		gbl_panel.rowHeights = new int[]{0};
		gbl_panel.columnWeights = new double[]{Double.MIN_VALUE};
		gbl_panel.rowWeights = new double[]{Double.MIN_VALUE};
		panel.setLayout(gbl_panel);
		frame.getContentPane().add(scrollPane);
		
	}
	
	public void addLiztaObszarow (JComponent komp){
	    GridBagConstraints gbc = new GridBagConstraints();
	    gbc.gridwidth = GridBagConstraints.REMAINDER;
	    gbc.anchor = GridBagConstraints.FIRST_LINE_END;
	    gbc.weightx = 1;
	    gbc.fill = GridBagConstraints.HORIZONTAL;
	    
	    Dimension index = panel.size();
	    this.panel.add(komp, gbc,index.height-1);
	}

}
